﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using T.FAS.Runtime.Base.Dao;
using T.FAS.Runtime.Base.Entity;
using T.FAS.Runtime.Base.Service;
using T.FAS.Runtime.Base.SGSPI;
using T.ServiceComponent.Kernel.Service;

namespace T.FAS.Runtime.Base.SGPlugin
{
    [SGService]
    public class QueryPlanSGService : IQueryPlanService
    {
        readonly QueryPlanService service = new QueryPlanService();
        /// <summary>
        /// 获取查询方案列表
        /// </summary>
        /// <returns></returns>
        public List<QueryPlan> GetQueryPlanList(string pageID, string DQID)
        {
            if (string.IsNullOrEmpty(pageID))
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.GetQueryPlanList.pageID");
            if (string.IsNullOrEmpty(DQID))
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.GetQueryPlanList.DQID");
            return service.GetQueryPlanList(pageID, DQID);
        }
        /// <summary>
        /// 创建或更新
        /// </summary>
        /// <param name="queryPlan"></param>
        [SGService(ServiceID = "FASR-CreateOrUpdateQueryPlan")]
        public Dictionary<string, string> CreateOrUpdateQueryPlan(QueryPlan queryPlan)
        {
            if (queryPlan == null)
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.CreateOrUpdateQueryPlan.queryPlan");
            return service.CreateOrUpdateQueryPlan(queryPlan);
        }
        /// <summary>
        /// 获取查询方案列表
        /// </summary>
        /// <returns></returns>
        public List<QueryPlan> GetQueryPlanListV2(QueryPlanFilter queryPlanFilter)
        {
            if (queryPlanFilter == null)
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.GetQueryPlanListV2.queryPlanFilter");
            if (string.IsNullOrEmpty(queryPlanFilter.PageID))
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.GetQueryPlanListV2.queryPlanFilter.PageID");
            return service.GetQueryPlanListV2(queryPlanFilter);
        }
        /// <summary>
        /// 获取查询方案列表不带明细
        /// </summary>
        /// <returns></returns>
        public List<QueryPlan> GetQueryPlanListV3(QueryPlanFilter queryPlanFilter)
        {
            if (queryPlanFilter == null)
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.GetQueryPlanListV2.queryPlanFilter");
            if (string.IsNullOrEmpty(queryPlanFilter.PageID))
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.GetQueryPlanListV2.queryPlanFilter.PageID");
            return service.GetQueryPlanListV3(queryPlanFilter);
        }
        /// <summary>
        /// 根据ID查询方案
        /// </summary>
        /// <param name="planId"></param>
        /// <returns></returns>
        public QueryPlan GetQueryPlanV2(string planId)
        {
            if (string.IsNullOrEmpty(planId))
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.GetQueryPlanV2.planId");
            return service.GetQueryPlanV2(planId);
        }
        /// <summary>
        /// 创建或更新
        /// </summary>
        /// <param name="queryPlan"></param>
        public Dictionary<string, string> CreateOrUpdateQueryPlanV2(QueryPlan queryPlan)
        {
            if (queryPlan == null)
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.CreateOrUpdateQueryPlanV2.queryPlan");
            return service.CreateOrUpdateQueryPlanV2(queryPlan);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        public Dictionary<string, string> DeleteQueryPlan(string id)
        {
            if (string.IsNullOrEmpty(id))
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.DeleteQueryPlan.id");
            return service.DeleteQueryPlan(id);
        }
        /// <summary>
        /// 保存查询方案列表
        /// </summary>
        public Dictionary<string, string> SaveQueryPlans(List<QueryPlan> queryPlans)
        {
            if (queryPlans == null)
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.SaveQueryPlans.queryPlans");
            return service.SaveQueryPlans(queryPlans);
        }
        /// <summary>
        /// 置顶
        /// </summary>
        /// <param name="planID"></param>
        /// <param name="topType">0置顶 1取消置顶</param>
        /// <returns></returns>
        public Dictionary<string, string> TopQueryPlan(string planID, int topType)
        {
            if (string.IsNullOrEmpty(planID))
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.TopQueryPlan.planID");
            return service.TopQueryPlan(planID, topType);
        }
        /// <summary>
        /// 分享
        /// </summary>
        public Dictionary<string, string> ShareQueryPlan(QueryPlan queryPlan, List<QueryPlan> shareUsers)
        {
            if (queryPlan == null)
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.ShareQueryPlan.queryPlan");
            if (shareUsers == null)
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.ShareQueryPlan.shareUsers");
            return service.ShareQueryPlan(queryPlan, shareUsers);
        }
        /// <summary>
        /// 更新查询方案
        /// </summary>
        public Dictionary<string, string> UpdateQueryPlan(string planID, Dictionary<string, object> param)
        {
            if (string.IsNullOrEmpty(planID))
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.UpdateQueryPlan.planID");
            return service.UpdateQueryPlan(planID, param);
        }

        /// <summary>
        /// 加入共享方案
        /// </summary>
        public Dictionary<string, string> JoinQueryPlan(QueryPlan queryPlan, List<QueryPlan> shareUsers)
        {
            if (queryPlan == null)
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.JoinQueryPlan.queryPlan");
            if (shareUsers == null)
                throw new FasException(BaseExceptionCode.ParamIsNullError, "QueryPlanSGService.JoinQueryPlan.shareUsers");
            return service.JoinShareQueryPlan(queryPlan, shareUsers);
        }
    }
}
